<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class track{
    private $userName = '';
    public function __construct(){
        $data = $this->getPrePage();
        echo $data;
    }
    //设定COOKIE值
    private function setCookie($userName){
        setcookie("hairExtensionBusUserName",$userName,time()+3600*24*365*3);
    }
    //通过时间戳获得唯一的用户名
    private function createUserName(){
        $this->userName = "Name_".time();
        return $this->userName;
    }
    //返回设定的COOKIE值
    private function getCookie(){
        $this->userName = $this->createUserName();
        if(!isset($_COOKIE['hairExtensionBusUserName'])){
            $this->setCookie($this->userName);
        }
        return $_COOKIE['hairExtensionBusUserName'];
    }
    private function getBrowserVersion(){
        return $_SERVER['HTTP_USER_AGENT'];
    }
    //获得用户的IP
    private function get_onlineip() {
        $onlineip = '';
        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
            $onlineip = getenv('HTTP_CLIENT_IP');
        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
            $onlineip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
            $onlineip = getenv('REMOTE_ADDR');
        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
            $onlineip = $_SERVER['REMOTE_ADDR'];
        }
        return $onlineip;
    }
    private function getCurrentPage(){
        return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }
    private function getPrePage(){
        $prePage = '';
        if(empty($_SESSION['HTTP_REFERER'])){
            $prePage = '';
        }else{
            $prePage = $_SESSION['HTTP_REFERER'];
        }
        return $_SERVER['HTTP_HOST'].$prePage;
    }
}
$t = new track;
?>
